package warm100;

import leetcode_181_200.maxProfit_188;
import leetcode_181_200.numIslands_200;
import leetcode_201_220.countPrimes_204;
import leetcode_201_220.isHappy_202;
import leetcode_201_220.rangeBitwiseAnd_201;
import leetcode_201_220.reverseList_206;
import org.junit.Test;
import utils.ListNode;
import utils.TreeNode;

import java.util.Arrays;

public class Test100 {

    @Test
    //数字范围按位与
    public void test201() {
        int[] nums = new int[]{0, 1, 0, 3, 12};
        new moveZeroes_283().moveZeroes1(nums);
    }

    @Test
    //找到字符串中所有字母异位词
    public void test438() {
        String s = "cbaebabacd", p = "abc";
//        String s = "acdcaeccde", p = "c";
        System.out.println(new findAnagrams_438().findAnagrams2(s,p));
    }

    @Test
    //数字范围按位与
    public void test560() {
        int[] nums = new int[]{1,-1,0};
        System.out.println(new subarraySum_560().subarraySum(nums,0));
    }

    @Test
    //和为 K 的子数组
    public void test239() {
        int[] nums = new int[]{1,3,-1,-3,5,3,6,7};
        System.out.println(Arrays.toString(new maxSlidingWindow_239().maxSlidingWindow(nums, 3)));
    }

    @Test
    //除自身以外数组的乘积
    public void test238() {
        int[] nums = new int[]{-1,1,0,-3,3};
        System.out.println(Arrays.toString(new productExceptSelf_238().productExceptSelf(nums)));
    }

    @Test
    // 搜索二维矩阵 II
    public void test240() {
        int[][] matrix = {{1,4,7,11,15},{2,5,8,12,19},{3,6,9,16,22},{10,13,14,17,24},{18,21,23,26,30}};
        System.out.println(new searchMatrixsearchMatrix_240().searchMatrix(matrix,5));
    }

    @Test
    // 回文链表
    public void test234() {
        ListNode head1=new ListNode(1);
        ListNode head2=new ListNode(0);
        ListNode head3=new ListNode(0);
        ListNode head4=new ListNode(1);
        head1.next=head2;
        head2.next=head3;
 //       head3.next=head4;
        System.out.println(new isPalindrome_234().isPalindrome(head1));
    }

    @Test
    // 回文链表
    public void test543() {
        TreeNode treeNode1=new TreeNode(1);
        TreeNode treeNode2=new TreeNode(2);
        TreeNode treeNode3=new TreeNode(3);
        TreeNode treeNode4=new TreeNode(4);
        TreeNode treeNode5=new TreeNode(5);

        treeNode1.left=treeNode2;
        treeNode1.right=treeNode3;

        treeNode2.left=treeNode4;
        treeNode2.right=treeNode5;
        System.out.println(new diameterOfBinaryTree_543().diameterOfBinaryTree(treeNode1));
    }

    @Test
    // 二叉搜索树中第 K 小的元素
    public void test230() {
        TreeNode treeNode1=new TreeNode(2);
        TreeNode treeNode2=new TreeNode(1);
        TreeNode treeNode3=new TreeNode(3);
//        TreeNode treeNode4=new TreeNode(1);
//        TreeNode treeNode5=new TreeNode(4);

        treeNode1.left=treeNode2;
        treeNode1.right=treeNode3;
////        treeNode1.right=treeNode3;
//        treeNode2.left=treeNode4;
        System.out.println(new kthSmallest_230().kthSmallest(treeNode1,3));
    }

    @Test
    //划分字母区间
    public void test763() {
        String s = "ababcbacadefegdehijhklij";
        System.out.println(new partitionLabels_763().partitionLabels(s));
    }

    @Test
    //路径总和 III
    public void test437() {
        TreeNode treeNode1=new TreeNode(10);
        TreeNode treeNode2=new TreeNode(5);
        TreeNode treeNode3=new TreeNode(-3);
        TreeNode treeNode4=new TreeNode(3);
        TreeNode treeNode5=new TreeNode(2);
        TreeNode treeNode6=new TreeNode(11);
        TreeNode treeNode7=new TreeNode(3);
        TreeNode treeNode8=new TreeNode(-2);
        TreeNode treeNode9=new TreeNode(1);

//        treeNode1.left=treeNode2;
//        treeNode1.right=treeNode3;
//        treeNode2.left=treeNode4;
//        treeNode2.right=treeNode5;
//        treeNode3.right=treeNode6;
//        treeNode4.left=treeNode7;
//        treeNode4.right=treeNode8;
//        treeNode5.right=treeNode9;
        System.out.println(new pathSum_437().pathSum(treeNode1,0));
    }

    @Test
    //路径总和 III
    public void test236() {
        TreeNode treeNode1=new TreeNode(3);
        TreeNode treeNode2=new TreeNode(5);
        TreeNode treeNode3=new TreeNode(1);
        TreeNode treeNode4=new TreeNode(6);
        TreeNode treeNode5=new TreeNode(2);
        TreeNode treeNode6=new TreeNode(0);
        TreeNode treeNode7=new TreeNode(8);
        TreeNode treeNode8=new TreeNode(7);
        TreeNode treeNode9=new TreeNode(4);

        treeNode1.left=treeNode2;
        treeNode1.right=treeNode3;
        treeNode2.left=treeNode4;
        treeNode2.right=treeNode5;
        treeNode3.left=treeNode6;
        treeNode3.right=treeNode7;
        treeNode5.left=treeNode8;
        treeNode5.right=treeNode9;
        System.out.println(new lowestCommonAncestor_236()
                .lowestCommonAncestor(treeNode1,treeNode2,treeNode9).val);
    }

    @Test
    //腐烂的橘子
    public void test994() {
        int[][] grid={{2,1,1},
                {1,1,0},
                {0,1,1}};
        System.out.println(new orangesRotting_994().orangesRotting(grid));
    }

    @Test
    //课程表
    public void test207() {
        int[][] grid={{1,0},
                {0,1}};
        System.out.println(new canFinish_207().canFinish(2,grid));
    }

    @Test
    //实现 Trie (前缀树)
    public void test208() {
        Trie_208 trie = new Trie_208();
        trie.insert("apple");
        trie.search("apple");   // 返回 True
        trie.search("app");     // 返回 False
        trie.startsWith("app"); // 返回 True
        trie.insert("app");
        trie.search("app");     // 返回 True

    }

    @Test
    //划分字母区间
    public void test394() {
        String s = "100[leetcode]";
        System.out.println(new decodeString_394().decodeString(s));
    }

    @Test
    //除自身以外数组的乘积
    public void test793() {
        int[] nums = new int[]{89,62,70,58,47,47,46,76,100,70};
        System.out.println(Arrays.toString(new dailyTemperatures_793().dailyTemperatures(nums)));
    }

    @Test
    //215. 数组中的第K个最大元素
    public void test215() {
        int[] nums = new int[]{3,2,3,1,2,4,5,5,6};
        System.out.println(new findKthLargest_215().findKthLargest2(nums,4));
    }

    @Test
    // 前 K 个高频元素
    public void test347() {
        int[] nums = new int[]{5,3,1,1,1,3,73,1};
        System.out.println(Arrays.toString(new topKFrequent_347().topKFrequent3(nums, 1)));
    }


}
